#pragma once
#include "aip-cpp-sdk-4.16.7/speech.h"
#include "log.hpp"


class ASRClient {
public:
    using ptr = std::shared_ptr<ASRClient>;
    ASRClient(const std::string app_id, const std::string &ak, const std::string &sk)
        :_client(app_id, ak, sk){}

    std::string recognize(const std::string &speech_data, std::string& err_msg) {
        Json::Value result = _client.recognize(speech_data, "pcm", 16000, aip::null);
        if(result["err_no"].asInt()) {
            err_msg = result["err_msg"].asString();
            LOG_ERROR("语音识别失败: {}", err_msg);
            return "";
        }
        err_msg = "";
        return result["result"][0].asString();
    }
private:
    aip::Speech _client;
};